const state = {
  cartItemCount: 0 // 购物车数量
};

const mutations = {
  // 更新购物车数量
  SET_CART_COUNT(state, count) {
    state.cartItemCount = count;
    // 同步到localStorage
    localStorage.setItem('cartItemCount', count);
  }
};

const actions = {
  // 初始化购物车数量
  initCartCount({ commit }) {
    const count = localStorage.getItem('cartItemCount') || 0;
    commit('SET_CART_COUNT', parseInt(count));
  },
  // 更新购物车数量
  updateCartCount({ commit }, count) {
    commit('SET_CART_COUNT', count);
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};